{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pyESN'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 3\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 只有信号，没有噪声\u001b[39;00m\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyESN\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ESN\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmatplotlib\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pyplot \u001b[38;5;28;01mas\u001b[39;00m plt\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mscipy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mio\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01msio\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pyESN'"
     ]
    }
   ],
   "source": [
    "# 只有信号，没有噪声\n",
    "import numpy as np\n",
    "from pyESN import ESN\n",
    "from matplotlib import pyplot as plt\n",
    "import scipy.io as sio\n",
    "%matplotlib inline\n",
    "\n",
    "# 导入数据\n",
    "# data = np.load('./data/hundun.npy') #  http://minds.jacobs-university.de/mantas/code\n",
    "data=sio.loadmat('output.npy')\n",
    "\n",
    "esn = ESN(n_inputs = 3,\n",
    "          n_outputs = 3,\n",
    "          n_reservoir = 3500,\n",
    "          spectral_radius = 1.2,\n",
    "          sparsity=0.2,\n",
    "          noise = 0.005,\n",
    "          random_state=23)\n",
    "\n",
    "trainlen = 8000\n",
    "future = 100\n",
    "\n",
    "pred_training = esn.fit(np.ones((trainlen,3)),data[:trainlen])\n",
    "prediction = esn.predict(np.ones((future,3)))\n",
    "print(\"test error: \\n\"+str(np.sqrt(np.mean((prediction.flatten() - data[trainlen:trainlen+future].flatten())**2))))\n",
    "\n",
    "plt.figure(figsize=(11,1.5))\n",
    "\n",
    "# 只展示训练和预测部分\n",
    "plt.plot(range(0,trainlen+future),data[0:trainlen+future],'k',label=\"target system\")\n",
    "# plt.plot(range(trainlen,trainlen+future),prediction,'r', label=\"free running ESN\")\n",
    "\n",
    "# 只展示预测部分\n",
    "# plt.plot(range(trainlen,trainlen+future),data[trainlen:trainlen+future],'k',label=\"target system\")\n",
    "# plt.plot(range(trainlen,trainlen+future),prediction,'r', label=\"free running ESN\")\n",
    "\n",
    "lo,hi = plt.ylim()\n",
    "plt.plot([trainlen,trainlen],[lo+np.spacing(1),hi-np.spacing(1)],'k:')\n",
    "plt.legend(loc=(0.61,1.1),fontsize='x-small')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
